<!DOCTYPE html>
<html lang="en">
<head>
    <div th:include="base-libs-easyui :: base-libs-easyui" />
    <title>机构资源接入信息</title>
    <style>
        body {
            padding: 0px 10px;
        }
        .form-table input, textarea{
            width: 610px!important;
            padding-left: 4px;
        }
        .form-table textarea{
            height: 130px;
        }
        .form-table select{
            width: 615px!important;
        }
        .tabs-header{
            border-top: none!important;
        }
    </style>
    <script type="text/javascript">
        /**是否下拉框数据源*/
        var sfDs = [
            {
                XMDM: "0"
                ,XMMC: "否"
            }
            ,{
                XMDM: "1"
                ,XMMC: "是"
            }
        ];
        $(function() {
            $("body").registerManagerPage({
                cacheTables: ["TB_ZY_JGZYJRMS"]
                ,callback: initView
            });
        });

        function initView(cacheData){
            $("#btnClose").on("click", btnCloseHandler);
            $("#btnSave").on("click", btnSaveHandler);
            /*是否下拉框赋值*/
            $("select[name='SFJR']").each(function(){
                $(this).createOptions(sfDs);
            });
            initJrms(cacheData);
            initData();
        }

        function initData(){
            var yljgxx = StoreCache.getCache("cache_zyjr_yljgxx");
            $("body").data("yljgxx", yljgxx);
            var PTJGID = yljgxx["PTJGID"];
            queryZyjrxx(PTJGID);
        }

        /**初始化接入模式下拉框*/
        function initJrms(cacheData){
            /*机构资源接入模式*/
            var TB_ZY_JGZYJRMS = cacheData["TB_ZY_JGZYJRMS"];
            $("table[ZYLX]").each(function(){
                var ZYLX = $(this).attr("ZYLX");
                var select = $(this).find("select[name='JRMS']");
                var ds = []
                $.each(TB_ZY_JGZYJRMS, function(index, item){
                    var LXDM = item["LXDM"];
                    if(LXDM == ZYLX){
                        ds.push(item);
                    }
                })
                $(select).createOptions(ds);
            })
        }

        /**查询当前机构配置的资源接入信息*/
        function queryZyjrxx(PTJGID){
            $.QuickRemote.AjaxJson("queryZyjrxx", queryZyjrxxHandler, {PTJGID: PTJGID});
        }
        function queryZyjrxxHandler(result){
            if(result){
                $.each(result, function(index, item){
                    var ZYLX = item["ZYLX"];
                    $("table[ZYLX='" + ZYLX + "']").find(".form-control").each(function(){
                        var name = $(this).attr("name");
                        var value = item[name];
                        $(this).QuickField("setData", value);
                    });
                })
            }
        }

        /**保存回调*/
        function btnSaveHandler(){
            if($(".form-control").QuickValidate()){
                var data = getData();
                data = JSON.stringify(data);
                var yljgxx = $("body").data("yljgxx");
                var PTJGID = yljgxx["PTJGID"];
                $.QuickRemote.AjaxJson("saveZyJrxx", saveJrxxHandler, {PTJGID: PTJGID, zyjrxx: data});
            }
        }
        function saveJrxxHandler(result){
            var state = result["state"];
            if(state)
            {
                $.QuickAlert.alertNormal("保存成功", {callback: function(){
                    $("#btnClose").trigger("click");
                }});
            }
            else
            {
                var info = result["info"];
                $.QuickAlert.alertFail({content: info["faultInfo"]});
            }
        }

        /**获取数据*/
        function getData(){
            var data = [];
            var yljgxx = $("body").data("yljgxx");
            var PTJGID = yljgxx["PTJGID"];
            $("table[ZYLX]").each(function() {
                var ZYLX = $(this).attr("ZYLX");
                var params = {ZYLX: ZYLX, PTJGID: PTJGID};
                $(this).find(".form-control").each(function(){
                    var name = $(this).attr("name");
                    var value = $(this).QuickField("getData");
                    params[name] = value;
                });
                data.push(params);
            });
            return data;
        }

        /**关闭回调*/
        function btnCloseHandler(){
            parent.layer.closeAll();
        }
    </script>
</head>
<body class="easyui-layout">
    <div region="center" style="border: none;">
        <div class="easyui-tabs" fit="true">
            <div title="预约转诊">
                <table ZYLX="01" class="form-table">
                    <tr>
                        <td class="td-text">
                            <label>是否接入</label>
                        </td>
                        <td class="td-content">
                            <select name="SFJR" class="form-control" quick-config="label:'预约转诊是否接入', validateProxy:'notNull'"></select>
                        </td>
                    </tr>
                    <tr>
                        <td class="td-text">
                            <label>接入模式</label>
                        </td>
                        <td class="td-content">
                            <select name="JRMS" class="form-control" ></select>
                        </td>
                    </tr>
                    <tr>
                        <td class="td-text">
                            <label>预约转诊地址</label>
                        </td>
                        <td class="td-content">
                            <input name="JRDZ" class="form-control">
                        </td>
                    </tr>
                    <tr>
                        <td class="td-text">
                            <label>参数</label>
                        </td>
                        <td class="td-content">
                            <textarea name="PARAMS" class="form-control"></textarea>
                        </td>
                    </tr>
                </table>
            </div>
            <div title="医技预约">
                <table ZYLX="02" class="form-table">
                    <tr>
                        <td class="td-text">
                            <label>是否接入</label>
                        </td>
                        <td class="td-content">
                            <select name="SFJR" class="form-control" quick-config="label:'医技预约是否接入', validateProxy:'notNull'"></select>
                        </td>
                    </tr>
                    <tr>
                        <td class="td-text">
                            <label>接入模式</label>
                        </td>
                        <td class="td-content">
                            <select name="JRMS" class="form-control"></select>
                        </td>
                    </tr>
                    <tr>
                        <td class="td-text">
                            <label>接入地址</label>
                        </td>
                        <td class="td-content">
                            <input name="JRDZ" class="form-control">
                        </td>
                    </tr>
                    <tr>
                        <td class="td-text">
                            <label>参数</label>
                        </td>
                        <td class="td-content">
                            <textarea name="PARAMS" class="form-control"></textarea>
                        </td>
                    </tr>
                </table>
            </div>
            <div title="床位预约">
                <table ZYLX="03" class="form-table">
                    <tr>
                        <td class="td-text">
                            <label>是否接入</label>
                        </td>
                        <td class="td-content">
                            <select name="SFJR" class="form-control" quick-config="label:'床位预约是否接入', validateProxy:'notNull'"></select>
                        </td>
                    </tr>
                    <tr>
                        <td class="td-text">
                            <label>接入模式</label>
                        </td>
                        <td class="td-content">
                            <select name="JRMS" class="form-control"></select>
                        </td>
                    </tr>
                    <tr>
                        <td class="td-text">
                            <label>接入地址</label>
                        </td>
                        <td class="td-content">
                            <input name="JRDZ" class="form-control">
                        </td>
                    </tr>
                    <tr>
                        <td class="td-text">
                            <label>参数</label>
                        </td>
                        <td class="td-content">
                            <textarea name="PARAMS" class="form-control"></textarea>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
    <div region="south" style="height: 41px; padding-top: 6px;">
        <button id="btnClose" type="button" style="margin-right: 10px; float: right;">关闭</button>
        <button id="btnSave" type="button" style="margin-right: 10px; float: right;">保存</button>
    </div>
</body>
</html>